package cn.weiwh.mailsend.mail.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;

import java.io.File;

public class MoveFileUtil {
    private static final Logger logger= LoggerFactory.getLogger(MoveFileUtil.class);
    public static void moveFile(File from, File to){
        try {

            if(!to.exists()){//判断文件夹是否创建，没有创建则创建新文件夹
                to.mkdirs();
            }
            SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-"); //格式化当前系统日期yyyy-MM-dd-HH-mm:ss:ms"
            String dateTime = dateFm.format(new java.util.Date());
            if (from.renameTo(new File(to.getPath()+"/"+dateTime+ from.getName()))) {
                logger.info("wwh---File is moved successful!");
            } else {
                logger.info("wwh---File is failed to move!");
            }
        } catch (Exception e) {
            logger.info("wwh---创建文件夹出错！");
            e.printStackTrace();
        }
    }


}
